package cn.mygweb.common.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.mygweb.common.mapper.SysVisitMapper;
import cn.mygweb.common.pojo.SysVisit;
import cn.mygweb.common.service.SysVisitService;
import lombok.extern.slf4j.Slf4j;

/** 
* <p>Title: SysVisitServiceImpl.java</p>
* <p>Description: 系统访问记录业务层实现类</p>  
* @author gxb 
* @date 2019年12月1日 
* <p>Copyright: Copyright (c) 2019</p>
* <p>Company: www.mygweb.cn</p> 
*/
@Service
@Slf4j
public class SysVisitServiceImpl implements SysVisitService {

	@Autowired
	private Sid sid;
	
	@Autowired
	private SysVisitMapper sysVisitMapper;

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public void AddOneCount(int type) {
		SysVisit record = new SysVisit();
		record.setType(type);
		SysVisit sv = sysVisitMapper.selectOne(record);
		int count = 1;
		if(sv == null) {
			record.setId(sid.nextShort());
			record.setCount(count);
			record.setRemark("备注信息");
			sysVisitMapper.insertSelective(record);
		}else {
			count += sv.getCount();
			sv.setCount(count);
			sysVisitMapper.updateByPrimaryKeySelective(sv);
		}
	}

	@Override
	public int selectCountByType(int type) {
		int count = 0;
		SysVisit record = new SysVisit();
		record.setType(type);
		SysVisit sv = sysVisitMapper.selectOne(record);
		if(sv != null) {
			count = sv.getCount();
		}
		return count;
	}
	
}
